
<h1><span class="yiyi-st" id="yiyi-12">numpy.eye</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.eye.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.eye.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.eye"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">eye</code><span class="sig-paren">(</span><em>N</em>, <em>M=None</em>, <em>k=0</em>, <em>dtype=&lt;type &apos;float&apos;&gt;</em><span class="sig-paren">)</span><a class="reference external" href="http://github.com/numpy/numpy/blob/v1.11.3/numpy/lib/twodim_base.py#L192-L241"><span class="viewcode-link">[source]</span></a></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">返回一个2-D数组，其中一个在对角线上，零在其他地方。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-15">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-16"><strong>N</strong>：int</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-17">输出中的行数。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-18"><strong>M</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">输出中的列数。</span><span class="yiyi-st" id="yiyi-20">如果为None，默认为<em class="xref py py-obj">N</em>。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-21"><strong>k</strong>：int，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-22">对角线索引：0（默认）是指主对角线，正值是指上对角线，负值是指下对角线。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-23"><strong>dtype</strong>：数据类型，可选</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-24">返回数组的数据类型。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-25">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-26"><strong>I</strong>：形状的数组（N，M）</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-27">一个数组，其中所有元素都等于零，除了<em class="xref py py-obj">k</em>对角线，其值等于1。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-28">也可以看看</span></p>
<dl class="last docutils">
<dt><span class="yiyi-st" id="yiyi-29"><a class="reference internal" href="numpy.identity.html#numpy.identity" title="numpy.identity"><code class="xref py py-obj docutils literal"><span class="pre">identity</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-30">（几乎）等效函数</span></dd>
<dt><span class="yiyi-st" id="yiyi-31"><a class="reference internal" href="numpy.diag.html#numpy.diag" title="numpy.diag"><code class="xref py py-obj docutils literal"><span class="pre">diag</span></code></a></span></dt>
<dd><span class="yiyi-st" id="yiyi-32">对角2-D数组由用户指定的1-D数组组成。</span></dd>
</dl>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-33">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="nb">int</span><span class="p">)</span>
<span class="go">array([[1, 0],</span>
<span class="go">       [0, 1]])</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">eye</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="n">k</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="go">array([[ 0.,  1.,  0.],</span>
<span class="go">       [ 0.,  0.,  1.],</span>
<span class="go">       [ 0.,  0.,  0.]])</span>
</pre></div>
</div>
</dd></dl>
